package com.cfgj.web;

import com.cfgj.entity.UserInfo;
import com.cfgj.entity.Vo.UserVo;
import com.cfgj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    public String showUserList(Model model, Integer page, Integer size){
        if (page==null||page==0) {
            page = 1;
        }
        List<UserVo> list = userService.findUserbyStatus(page,size);
        Integer counts = userService.findcount();
        model.addAttribute("lists",list);
        model.addAttribute("curr",page);
        model.addAttribute("count",counts);
        return "/admin/member-list";
    }

    @RequestMapping("/userlist")
    public String accUserList(Model model, Integer page, Integer size){
        if (page==null||page==0) {
            page = 1;
        }
        List<UserInfo> list = userService.accUserbyStatus(page, size);
        Integer counts = userService.usercount();
        model.addAttribute("lists",list);
        model.addAttribute("curr",page);
        model.addAttribute("count",counts);
        return "/admin/member-info";
    }

    @RequestMapping("/upuserStatus")
    @ResponseBody
    public String updateStatus(Integer id, Integer status){
        userService.updateUserStatus(id, status);
        return "redirect:/user/list";
    }
    @RequestMapping("/upStatus")
    @ResponseBody
    public String updateuserStatus(Integer id, Integer status){
        userService.updateStatus(id, status);
        return "redirect:/user/userlist";
    }
}
